
function getUrlParams() {
    let url = location.href;
    let regExp = /.*\?([^\?]+)/
    let query = {};//最终处理好的参数
    let search = regExp.exec(url);
    //productid=23&NAME=123"
    // console.log(search);
    search = search[1];
    //有没有多个query参数,有的话肯定以&进行连接
    let searchArr = [];
    if (search.indexOf("&")) {
        searchArr = search.split("&")
    } else {
        search = search.split()
    }

    searchArr.forEach(item => {
        let queryArr = item.split("=");
        query[queryArr[0]] = queryArr[1]
    })

    return query
}

// `./bijia.html?categoryid=${categoryid}&title=${this.innerText}`categoryId
//`./bijia.html?categoryid=${categoryid}&title=${this.innerText}`
let query = getUrlParams();
// console.log(query);
query.text1 = unescape(decodeURI(query.text1))//编译中文
// console.log(query);
query.text1 = query.text1.replace(/#/g, '')
// console.log(query);
$("#a")[0].innerHTML = '&nbsp;' + query.text1 + '>'

$("#a").click(function () {
    history.back()
    // location.href = `./bijia.html?categoryid=${query.categoryId}&title=${query.text1}`
})
fn(query.productId)//图片
//==============================================

function fn(productid = 0) {
    //图片
    $.ajax({
        url: 'http://chst.vip:1234/api/getproduct',
        data: {
            productid: productid
        }
    }).then(res => {
        console.log(res);
        let html = ''
        res.result.forEach(item => {
            html += `
            <p>${item.productImg}</p>
            <p>${item.productName}</p>
            <p><span>当前最低价 ￥250</span><span>优质评论 250条</span></p>
            ${item.bjShop}
            `
        })
        $('#box')[0].innerHTML = html
        $("#aa")[0].innerHTML = res.result[0].productName
    })

    //评论
    $.ajax({
        url: 'http://chst.vip:1234/api/getproductcom',
        data: {
            productid: productid
        }
    }).then(res => {
        console.log(res);
        let html = ''
        res.result.forEach(item => {
            html += `
            <li>
            <p><span>${item.comName}</span><span>${item.comTime}</span></p>
            <p>${item.comContent}</p>
            <p><span>${item.comFrom}</span></p>
            </li>
            `
        })
        $("#ul")[0].innerHTML = html
    })


}




